<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>ZDH - 注册</title>
    <meta name="keywords" content="ZDH,响应式后台">
    <meta name="description" content="ZDH，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="img/favicon.ico"> <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <script>if(window.top !== window.self){ window.top.location = window.location;}</script>

</head>

<body class="gray-bg">

    <div class="middle-box text-center loginscreen   animated fadeInDown">
        <div>
            <div>

                <h1 class="logo-name">ZD</h1>

            </div>
            <h3>欢迎注册 ZD</h3>
            <p>创建一个ZD新账户</p>
            <form id="register_form" class="m-t" role="form" action="register_zdh" method="post">
                <div class="form-group">
                    <input id="userName" name="userName" type="text" class="form-control" placeholder="请输入用户名" required="">
                </div>
                <div class="form-group">
                    <input id="email" name="email" type="email" class="form-control" placeholder="请输入邮箱" required="">
                </div>
                <div class="form-group">
                    <input id="password" name="password" type="password" class="form-control" placeholder="请输入密码" required="">
                </div>
                <div class="form-group">
                    <input id="password2" name="password2" type="password" class="form-control" placeholder="请再次输入密码" required="">
                </div>
                <div class="form-group text-left">
                    <div class="checkbox i-checks">
                        <label class="no-padding">
                            <input id="check_agree" type="checkbox"><i></i> 我同意注册协议</label>
                    </div>
                </div>
                <button type="button" class="btn btn-primary block full-width m-b" οnsubmit='return false' onclick="register()">注 册</button>

                <p class="text-muted text-center"><small>已经有账户了？</small><a href="login.html">点此登录</a>
                </p>

            </form>
        </div>
    </div>

    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.6"></script>

    <!-- layer javascript -->
    <script src="js/plugins/layer/layer.min.js"></script>


    <!-- iCheck -->
    <script src="js/plugins/iCheck/icheck.min.js"></script>
    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });

        function register(){
            if( $('#userName').val().trim()==''){
                layer.msg("用户名不能为空")
                return ;
            }

            var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            if(!myreg.test($('#email').val()))
            {
                layer.msg('请输入有效的邮箱!');
                return false;
            }

            if( $('#password').val()==''){
                layer.msg("密码不能为空")
                return ;
            }
            if( $('#password').val().trim()!=$('#password2').val().trim()){
                layer.msg("2次密码不一致")
                return ;
            }
            if( $('#check_agree').is(':checked')==false){
                layer.msg("请选择同意协议")
                return ;
            }

            $.ajax({
                type: 'POST',
                url: "register",
                dataType: 'json',
                data: $("#register_form").serialize(),
                //成功返回
                success: function (data) {
                    if(data.error !='' ){
                        layer.msg(data.error)
                    }else{
                        window.location.href="login"
                    }
                },
                //处理完成
                complete: function () {
                    console.info("complete")
                },
                //报错
                error: function (data) {
                    console.info("error: " + data.responseText);
                }
            });



        }

    </script>



</body>

</html>
